package com.histone.lib_download.localbroadcast;

import android.content.Context;
import android.content.Intent;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

/**
 * 本地广播发送类
 */
public class LocalBroadcastHolder {
    public static final String LOCAL_BROADCAST_ACTION = "com.robin.localbroadcast";
    public static final String BROADCAST_CODE = "broadcast_code";
    public static final String BROADCAST_FILE_INFO = "broadcast_file_info";
    /**
     * 下载成功
     */
    public static final int CODE_OK = 200;
    /**
     * 下载失败
     */
    public static final int CODE_ERROR = 203;
    /**
     * 错误 代码 空间不足
     */
    public static final int CODE_ERROR_NO_SPACE = 202;

    private static LocalBroadcastHolder localBroadcastHolder;

    public static LocalBroadcastHolder getInstance() {
        if (localBroadcastHolder == null) {
            localBroadcastHolder = new LocalBroadcastHolder();
        }
        return localBroadcastHolder;
    }

    public LocalBroadcastHolder sendBroadcast(Context context, Intent intent) {
        if (intent == null) return localBroadcastHolder;
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
        return localBroadcastHolder;
    }
}
